import gradio as gr

zh = {'admin': '123456'}


def denglu(zhanghao, mima):
    re = ""
    for i in zh:
        if zhanghao == i and mima == zh[i]:
            re = "登录成功"
        else:
            re = "账号或密码错误"
    return re


def zhuce(zhanghao, mima):
    for i in zh:
        if zhanghao == i:
            return "该账号已存在"
        else:
            zh[zhanghao] = mima
            print(zh)
            return "注册成功"


def chongzhi(zhanghao, mima):
    for i in zh:
        if zhanghao == i:
            zh[zhanghao] = mima
            print(zh)
            return "重置成功"
        else:
            return "该账号不存在"


with gr.Blocks() as demo:
    gr.Markdown("# 请登录您的账号")
    with gr.Column():
        inp1 = gr.Textbox(label="账号")
        inp2 = gr.Textbox(label="密码")
        with gr.Row():
            btn1 = gr.Button("登录", variant="primary")
            btn2 = gr.Button("注册")
        btn3 = gr.Button('重置密码', size='sm')
        out = gr.Textbox(label="结果")
        btn1.click(fn=denglu, inputs=[inp1, inp2], outputs=out)
        btn2.click(fn=zhuce, inputs=[inp1, inp2], outputs=out)
        btn3.click(fn=chongzhi, inputs=[inp1, inp2], outputs=out)

demo.launch()
